home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16357 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  72 lines

  1. Newsgroups: comp.lang.c++
  2. Path: in1.uu.net!shore!mv!usenet
  3. From: ENGR@GSSI.MV.COM (Michael Furman)
  4. Subject: Re: Help: very simple(?) array problem
  5. Message-ID: <DpnHMA.IMy@mv.mv.com>
  6. Mime-Version: 1.0
  7. Content-Type: Text/Plain; charset=US-ASCII
  8. Organization: GSSI
  9. Date: Wed, 10 Apr 1996 14:30:09 GMT
  10. References: <4kejrv$ml2@kruuna.helsinki.fi>
  11. X-Newsreader: WinVN 0.99.7
  12. X-Nntp-Posting-Host: gssi.mv.com
  13.  
  14. In article <4kejrv$ml2@kruuna.helsinki.fi>, marjakan@cc.helsinki.fi says...
  15. >
  16. >I have tried to get a piece of code to work for couple of hours now and
  17. >I don't know any longer what is wrong with it. All seems OK with me, but
  18. >still compiler (both GNU-C++ and C++) give an error:
  19. >"initializer for scalar variable requires one element".
  20. >I'm totally confused.
  21. >
  22. >The code looks following...
  23. >
  24. >class Object
  25. >{
  26. >...
  27. > Object(char **name);
  28. >...
  29. >};
  30. >
  31. >Object::Object(char **name)
  32. >{
  33. > ...
  34. >}
  35. >
  36. >main()
  37. >{
  38. >    char **b={"First","Second"};
  39. >    Object a(b);
  40. >}
  41. >
  42. >If I change main() to
  43. >{
  44. >    Object a({"First","Second"});
  45. >}
  46. >
  47. >both compilers report "parse error before {" at that line which
  48. >contains Object a(...);
  49. >
  50. >I simply cannot understand what can be wrong, to me it looks just fine.
  51. >Can anyone help?
  52.  
  53. The best way to - take a book and look at it. And compiler message could
  54. help. Look at ARM 8.4.1 - initializers like yours may be used only in
  55. aggregate arrays. And you tried to apply it to pointer or class - that is
  56. incorrect.
  57.  
  58. The closest think you can do is:
  59.  
  60.   char * b[] = {"first", "second"};    
  61.  
  62.  
  63. -- 
  64. <<< If you received it by E-mail: it is a copy of post to the newsgroup >>>
  65. ---------------------------------------------------------------
  66. Michael Furman,                       (603)893-1109
  67. Geophysical Survey Systems, Inc.  fax:(603)889-3984
  68. 13 Klein Drive - P.O. Box 97          engr@gssi.mv.com 
  69. North Salem, NH 03073-0097            71543.1334@compuserve.com
  70. ---------------------------------------------------------------
  71.  
  72.